package cc.ufinity.networkdiagnose.widget;

import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import cc.ufinity.networkdiagnose.view.CfgActivity;
import cc.ufinity.networkdiagnose.view.R;

public class SettingWidget extends GeneralTestWidget {
	private LinearLayout accoutpeizhi;
	private LinearLayout phonenumber;
	private LinearLayout httppeizhi;
	private LinearLayout netpeizhi;
	private LinearLayout resultloadup;
	
	private Button backButton;

	// private ListView list;
	private Activity ctx;

	 public static int num = 1;

	public SettingWidget(Activity context) {
		super(context);
		num = 2;
		this.ctx = context;
		inflate(context, R.layout.setting_widget, this);
		// list=(ListView)findViewById(R.id.mylist);
		
		backButton = (Button)findViewById(R.id.test_btnback);

		accoutpeizhi = (LinearLayout) findViewById(R.id.zhanghaopeizhi);
		phonenumber = (LinearLayout) findViewById(R.id.beijihaomapeizhi);
		httppeizhi = (LinearLayout) findViewById(R.id.httppeizhi);
		netpeizhi = (LinearLayout) findViewById(R.id.wangluoceshipeizhi);
		resultloadup = (LinearLayout) findViewById(R.id.ceshijieguoshangchuan);
		
		backButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            	ctx.finish(); 
            }
        });

		accoutpeizhi.setOnClickListener(new AccoutpeizhiListener());
		phonenumber.setOnClickListener(new PhonenumberListener());
		httppeizhi.setOnClickListener(new HttppeizhiListener());
		netpeizhi.setOnClickListener(new NetpeizhiListener());
		resultloadup.setOnClickListener(new ResultloadupListener());
	}

	class AccoutpeizhiListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			num=3;
			accountConfig();
			// TODO Auto-generated method stub
		}
	}

	class PhonenumberListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			num=3;
			mobileConfig();
			// TODO Auto-generated method stub
		}
	}

	class HttppeizhiListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			num=3;
			httpConfig();
			// TODO Auto-generated method stub
		}
	}

	class NetpeizhiListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			num=3;
			pingConfig();
			// TODO Auto-generated method stub
		}
	}

	class ResultloadupListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			num=3;
			doUpload();
			// TODO Auto-generated method stub
		}
	}

	/*
	 * String[] menu = getResources().getStringArray(R.array.settingGridView);
	 * // int[] icons = new int[] { R.drawable.ftp_settings, R.drawable.people,
	 * R.drawable.phone, R.drawable.http_test, R.drawable.ping,
	 * R.drawable.upload_file }; int[] icons = new int[] {R.drawable.people,
	 * R.drawable.phone, R.drawable.http_test, R.drawable.ping,
	 * R.drawable.upload_file }; ListAdapter adapter = new MyAdapter(ctx, icons,
	 * menu); list.setAdapter(adapter);
	 */
	/*
	 * list.setOnItemClickListener(new OnItemClickListener() { public void
	 * onItemClick(AdapterView<?> arg0, View v, int index, long id) { num=3;
	 * switch (index) { case 0: ftpConfig(); break; case 0: accountConfig();
	 * break; case 1: mobileConfig(); break; case 2: httpConfig(); break; case
	 * 3: pingConfig(); break; case 4: doUpload(); break; } } }); }
	 */

	private void mobileConfig() {
		MyMobileCfgWidget mw = new MyMobileCfgWidget(ctx);
		ctx.setContentView(mw);
	}

	private void ftpConfig() {
		FtpConfigWidget fw = new FtpConfigWidget(ctx);
		ctx.setContentView(fw);
	}

	private void accountConfig() {
		AccountConfigWidget af = new AccountConfigWidget(ctx);
		ctx.setContentView(af);
	}

	private void httpConfig() {
		HttpConfigWidget af = new HttpConfigWidget(ctx);
		ctx.setContentView(af);
	}

	private void pingConfig() {
		PingConfigWidget af = new PingConfigWidget(ctx);
		ctx.setContentView(af);
	}

	private void doUpload() {
		FilesUploadWidget fu = new FilesUploadWidget(ctx);
		ctx.setContentView(fu);
	}

}
